\chapter{Implementation}
\label{ch:Implementation}
This chapter gives a glance to the implementation of the framework as well as the employed technologies.
We use Java as programming language to develop the framework due to its popularity in the research community. The framework is developed base on the Eclipse Modeling Framework Project. And for the AI planner, we adopt LPG-td which won the best planner prize in the International Planning Competition 2004\footnote{http://www.informatik.uni-freiburg.de/hoffmann/ipc-4/.}.

\section{Eclipse Modeling Framework}
Eclipse Modeling Framework project (EMF) \cite{EMF-08-BOOK,EMF-WEBSITE} is a modeling framework and code generation facility for building tools and other application based on a structured data model.

EMF provides tools to define the data model which saved in XMI format, and provides tool for generate runtime support Java classes. The generated classes include APIs allow user to construct viewer, editor for the data model. They also include a basic editor for the data model.

The interesting point (also the strength) of EMF is to support code regenerate. It means that users are able to customize generated code. When they need to update to model, EMF can regenerate the code without affecting to customized code. In this way, EMF provides a mechanism for developing model-based applications.

Generated code can run as ether a rich-client program (RCP), or an plugin of the Eclipse IDE. It inherits a powerful plug-in infrastructure of Eclipse IDE that allows user to customize the application by plug-in. It also provides an elegant user interface supporting Multiple-Document Interface (MDI) and dockable interface which the MDI editor sits in the center and other views are placed around (see figure \ref{fig:jasim-mainscreen}).

\begin{figure}
    \centering
    \includegraphics[width=0.8\textwidth]{figures/jasim-mainscreen.png}
    \caption{The MDI and dockable interface of an RCP.}
    \label{fig:jasim-mainscreen}
\end{figure}

\section{AI Planner}
As aforementioned, our framework relies on an off-the-shelf AI planner tool. We adopted LPG-td \cite{WEBSITE-LPG}, a fully automated system for solving planning problems, which supports PDDL 2.2 specification \cite{STEFAN-HOFFMANN-05-PDDL22}. The LPG-td is a fast planner with an easy, simple command interface, which supports both target platforms: Windows and Linux. However, as PDDL is a standard for the International Planning Competition, it is not difficult to move to other planners.

\section{Jasim Application} \label{sec:jasim}
This section discusses about the Jasim Application which is built on top of the framework. Although Jasim itself is not an self-reconfigurable STS,  it provides a GUI supporting designers in developing their STS. Jasim developers employ the EMF to develop an elegant, user-friendly, flexible and extensible tool. Most of functions of Jasim can be reused in developing other applications in a simplest way thank to the powerful Eclipse Plugin Architecture. The major features of Jasim are: ODM editor,  ODM solution generator, and ODM solution simulation.

\subsection{ODM Editor}
The ODM editor is an elegant MDI editor which allows users to open many ODM documents at the same time. There are two kinds of ODM documents:
\begin{itemize}
    \item \emph{Template document} is a variant of the ODM. The \emph{template document} contains
         \begin{inparaenum}[\itshape i\upshape)]
             \item sets of property descriptors for actor, goal and capability.
             \item list of available evaluators
             \item list of available custom reactions which can be used in define events
             \item list of predefine events.
         \end{inparaenum}
         These information can be shared between different ODM in a same domain. For example, the models of fire fighting are vary in different scenarios e.g., fire in buildings, fire in forests. But, the properties of actors, goals and capability in these scenario are somewhat similar as well as the event types and evaluators.
    \item \emph{Normal document} contains information of the potential organizational model and the event model for simulation.
\end{itemize}

In figure \ref{fig:jasim-editor-selection}, it is the ODM editor. Each of ODM document has fives subtabs. The \emph{Selection} tab is tree-like editor for the whole content of the ODM. When a object is selected, its properties are shown in the \emph{Properties} view in order to edit. The next three tabs, \emph{Actors, Goals}, and \emph{Capabilities}, are different view aspects of the ODM (see figure \ref{fig:jasim-editor-actors}). They are tabular editors whose columns are dynamically constructed based on the number property descriptors of the corresponding object. These editors provide users an easier way to edit objects' properties. The final \emph{PDDL} tab shows the PDDL code reflect to the editing model.

\begin{figure}
    \centering
    \subfigure[Selection tab]{
        \includegraphics[width=0.55\textwidth]{figures/jasim-editor-selection.png}
        \label{fig:jasim-editor-selection}
    }
    \subfigure[Actors tab]{
        \includegraphics[width=0.4\textwidth]{figures/jasim-editor-actors.png}
        \label{fig:jasim-editor-actors}
    }
    \caption{Jasim MDI editor of ODM document}
    \label{fig:jasim-editor}
\end{figure}

\subsection{ODM Solution Simulation}
The feature consists of different views supporting the solutions simulations as follows:
\begin{itemize}
    \item \emph{Solution List} (figure~\ref{fig:jasim-solution-list}) displays a list of generated solutions. From this view, users can view the solution detail, simulate selected solutions with/without events.
    \item \emph{PDDL Solution} (figure~\ref{fig:jasim-solution-view}) displays the detail of selected solutions as well as the PDDL code generating this solution. This information is extremely useful for the event simulation feature. It allows users to view PDDL script of each simulation node.
    \item \emph{Solution Simulation} (figure~\ref{fig:jasim-solution-simulation}) displays the execution of a solution. Each execute action has information about agent who is in charge of, the detail action and the starting time as well as ended time.
    \item \emph{Simulation Timeline} (figure~\ref{fig:jasim-simulation-timeline}) display the same information as \emph{Solution Simulation} view, but in a visual way. In this view, each actor occupies a swimlane which shows actions performed by this actor. Each action is presented by a round rectangle with different color, and a label on top e.g., D for DECOMPOSE action and P for PASSES. The rectangle's length determines the duration of this action in  virtual time. If a action is interrupt by a replan action, it is displayed with a red color.
    \item \emph{Event Simulation} (figure~\ref{fig:jasim-event-simulation}) displays the result of the event simulator. The simulation tree is shown of the left hand side, meanwhile the detail of selected simulation node is displayed on the right hand side. A summarized chart for the solutions' adaptation is also illustrated on the this side. In this chart, user is able to select different chart types and scalar evaluator evaluating simulation tree.

        When user selects a simulation tree node, the corresponding solution and solution's execution are shown in the \emph{PDDL Solution} and \emph{Simulation Timeline} views, respectively.
\end{itemize}

\begin{figure}[h]
    \centering
    \subfigure[Solution List] {
        \includegraphics[width=0.3\textwidth]{figures/jasim-solution-list.png}
        \label{fig:jasim-solution-list}
    }
    \subfigure[Pddl Solution] {
        \includegraphics[width=0.5\textwidth]{figures/jasim-solution-view.png}
        \label{fig:jasim-solution-view}
    }
    \subfigure[Solution Simulation] {
        \includegraphics[width=0.45\textwidth]{figures/jasim-solution-simulation.png}
        \label{fig:jasim-solution-simulation}
    }
    \subfigure[Simulation Timeline] {
        \includegraphics[width=0.45\textwidth]{figures/jasim-simulation-timeline.png}
        \label{fig:jasim-simulation-timeline}
    }
    \caption{Jasim's solution simulation's views.}
    \label{fig:jasim-simulation-views}
\end{figure}

\begin{figure}
    \centering
    \includegraphics[width=1\textwidth]{figures/jasim-event-simulation.png}\\
    \caption{Event simulation view.}
    \label{fig:jasim-event-simulation}
\end{figure}
